#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for (int i = l; i <= r; ++i)
const int N = 5e3 + 5; 
int n, T, a[N], b[N]; double ans, v[N], p[N]; 

int main () {
  freopen ("M.in", "r", stdin); 
  freopen ("M.out", "w", stdout); 
  scanf("%d", &T); 
  while (T--) {
    scanf("%d", &n), ans = 0; 
    rep(i, 1, n) {
      scanf("%d%d%lf", &a[i], &b[i], &p[i]); 
      v[i] = a[i] + p[i] * b[i]; 
    }
    sort(v + 1, v + n + 1); 
    rep(i, 1, n) ans += v[i] * (n - i + 1); 
    printf("%.15lf\n", ans); 
  }
  return 0; 
}